﻿using System;

namespace BankSystem
{
    public class Account
    {
        public string Id { get; set; }

        public decimal Money { get; set; }

        public string Pwd { get; set; }

        Random random = new Random();

        public Account(string id, decimal money, string pwd)
        {
            Id = id;
            Money = money;
            Pwd = pwd;
        }


        public virtual bool SaveMoney(decimal money) 
        {
            if(money < 0)
            {
                return false;
            }

            Money += money;
            return true;
        }

        public virtual bool WithdrawMoney(decimal money)
        {
            if(random.Next(1,3)==3)
            {
                throw new BadCashException("坏钞");
            }

            if(Money >= money)
            {
                Money -= money;
                return true;
            }
            return false;
        }

        public virtual bool IsMatch(string id, string pwd)
        {
            return Id == id && Pwd == pwd;
        }
    }
}
